// import from "../../apis/mine.js"
import apis from "../../http/apis"
export default {
	namespaced: true,
	state: {
		//初始列表数据
		// list: []
		carInfo: [],
		userInfo: {},
		//所有的地址
		addressInfo: [],
		//根据地址id查询地址
		addressDetailInfoByID: {}
	},
	mutations: {
		setLoveCar(state, data) {
			if (data.code == 1332) {
				state.carInfo = data.data
			}
			else {
				state.carInfo = []
			}

		},
		setUserDetailsInfo(state, data) {
			state.userInfo = data
		},
		setAddress(state, data) {
			state.addressInfo = data
		},
		setAddressByID(state, data) {
			state.addressDetailInfoByID = data
		}
	},
	actions: {
		//context
		async getMyLoveCarInfo(context, params) {
			// console.log(params)
			const data = await apis.getMyLoveCar();
			context.commit('setLoveCar', data)
			// return (data)
		},
		//获取该用户的所有详情信息
		async getUserInfoAll(context) {
			const data = await apis.getUserDetails();
			context.commit('setUserDetailsInfo', data.data)
		},
		//获取地址
		async getAddressAll(context) {
			const data = await apis.getAddressAll();
			context.commit('setAddress', data.data)
		},
		//新增地址
		async addAddressInfo(context, res) {
			const data = await apis.addUserAddress(res);
			return data;
		},
		//删除地址
		async delAddressOneInfo(context, params) {
			const data = await apis.delUserAddress(params)
			return data
		},
		//根据地址id查询地址
		async getAddressByIDInfo(context, par) {
			const data = await apis.getAddressByID(par)
			context.commit('setAddressByID', data.data)
		},
		//修改地址
		async updateAddressInfo(context, params) {
			const data = await apis.updateAddress(params);
			return data;
		},
		//修改头像
		async updateTouxiangInfo(context, params) {
			const data = await apis.updateUserTouxiang(params);
			return data;
		},
		//修改个人信息
		async updateUserInfoAll(context, params) {
			const data = await apis.updateUserInfo(params);
			return data
		}
	},
}
